package org.example.redpacket.controller;

import com.alibaba.fastjson.JSONObject;
import org.example.redpacket.handler.R;
import org.example.redpacket.model.dto.RedPacketDetailPageQryDTO;
import org.example.redpacket.model.vo.RedPacketDetailPageRspVO;
import org.example.redpacket.service.UserRedPacketDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * 用户领取红包详细相关的 Controller
 *
 * @author: hero生仔
 */
@RestController
@RequestMapping("/redPacketDetail")
public class RedPacketDetailController {
    @Autowired
    private UserRedPacketDetailService userRedPacketDetailService;

    @PostMapping("/redPacketDetailByPage")
    public R queryRedPacketDetailByPage(@RequestBody @Valid RedPacketDetailPageQryDTO redPacketDetailPageQryDTO) {
        List<RedPacketDetailPageRspVO> rsps = userRedPacketDetailService.qryRedPacketDetailByPage(redPacketDetailPageQryDTO);
        redPacketDetailPageQryDTO.setContinuesFlag(rsps.size() == redPacketDetailPageQryDTO.getPageSize());
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("redPacketDetailPageQryDTO", redPacketDetailPageQryDTO);
        jsonObject.put("RedPacketDetailPageRsp", rsps);
        return R.ok().setData(jsonObject);
    }
}
